import Global from '@/common/global.js' //全局封装方法
import store from '@/common/vuex.js' //全局仓储
import { createRouter, createWebHistory ,createWebHashHistory} from 'vue-router'


const routes = [
    {
        path: '/',
        redirect: "/login"
    },
    {
        path: '/login',
        name: 'login',
        meta: {title: "纬叶漫漫-蚂蚁日记",keepAlive: true},
        component: ()=>import('@/views/login/login'),
        children: [

        ]
    },
    {
        path: '/register',
        name: 'register',
        meta: {title:"注册",keepAlive:true},
        component: ()=>import('@/views/login/register'),
    },
    {
        path: '/home',
        name: 'home',
        component: ()=>import('@/views/home/home'),
        meta: {title: '首页',keepAlive: true},
        children: [
            {
                path: '/',
                meta: {title: '首页',keepAlive: true},
                component: ()=>import('@/views/home/home')
            },
            {
                path: '/linklist',
                name: 'linklist',
                meta: {title: '上报链接',keepAlive: true},
                component: () => import('@/views/home/link-list')
            }, {
                path: '/addlist',
                name: 'addlist',
                meta: {title: '添加链接',keepAlive: true},
                component: () => import('@/views/home/add-link')
            }, {
                path: '/callList',
                name: 'callList',
                meta: {title: '回调',keepAlive: true},
                component: () => import('@/views/home/call-list')
            }
        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    // console.log(to)

    console.log("----router is :" +  to.name)
    if (to.name=='login')  {
        next()
    }else if (to.meta.title) {
        document.title=to.meta.title;
        store.commit('pageJump', to)
        next()
    }else {
        //通知一下
        console.error('stop to errorPage')
        Global.toast('页面路径无效')
    }
});

export default router
